'''

126授权码    WPv9uZSFLKQrMVAZ
QQ邮箱授权码  cjiyqjhovahlbeeh

'''
import csv
import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.text import MIMEText # emial: 构建邮件 MIMEText: 文本对象
from email.mime.multipart import MIMEMultipart  #构建多个内容

send_account = 'mouringx@126.com'
reciver_account = ['740600577@qq.com']


def from_email():
    # 构建邮件对象
    data = MIMEMultipart()
    # 主题
    data['Subject'] = 'LCK Road To MSI Player Data'
    # 发送方
    data['From'] = send_account
    # 接收方
    data['To'] = ','.join(reciver_account)

    html_str = """
    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>Player Data</h1>
    <p>
        <img src="cid:testimg">
    </p>
</body>
</html>
    
    """
    data.attach(MIMEText(html_str, 'html', 'utf-8'))

    # 图片
    with open(r'R-C.jpg', 'rb') as fp:
        img_data = MIMEImage(fp.read())
        img_data.add_header('Content-ID', 'testimg')
        data.attach(img_data)



    # 附件
    with open(r'LCK 2025 Road to MSI - Player Stats - OraclesElixir.csv','r',encoding='utf-8') as f:
        attachment  = MIMEBase('application', 'octet-stream')
        attachment.set_payload(f.read())
        encoders.encode_base64(attachment)
        attachment.add_header('Content-Disposition', 'attachment; filename="LCK_Player_Data.csv"')
        data.attach(attachment)

    return data

def send_email():
    data = from_email()
    smtp = smtplib.SMTP_SSL('smtp.126.com', 465)

    # 授权码
    send_allow_pwd = 'WPv9uZSFLKQrMVAZ'
    smtp.login(send_account, send_allow_pwd)
    print('邮箱登录成功~~~~')

    # 发送邮件
    smtp.sendmail(send_account, reciver_account, data.as_string())

    #退出
    smtp.quit()

    print('send success')




if __name__ == '__main__':
     send_email()

